package me.qingy.programmatic;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
 * 没啥说的，和 IP 无效化一样
 *
 * @author qingy
 * @since 2021/8/19
 */
public class ReplaceSpace {

    public String replaceSpace(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (s.charAt(i) == ' ') {
                sb.append("%20");
            } else {
                sb.append(c);
            }
        }
        return sb.toString();
    }

    @Test
    public void testReplaceSpace() {
        Assertions.assertEquals("We%20are%20happy.", replaceSpace("We are happy."));
    }
}
